<?php

namespace App\Http\Controllers\Home;

use Amap;
use App\Facades\Sms;
use App\Messages\VerificationCodeMessage;
use App\Models\MsgFee;
use App\Models\Order;
use App\Services\PayService;
use App\Services\RouteService;
use App\Services\ShippingService;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Traits\File;

class IndexController extends Controller
{
    use File;

    public function index(Request $request)
    {
        echo '项目开发中...';
    }

    /**
     * 测试路由
     * @param Request $request
     */
    public function test(Request $request)
    {
        // 运单补偿测试
//        $msgFees = MsgFee::onWriteConnection()
////            ->where('out_trade_no', $request->get('out_trade_no'))
//            ->where('pay_status', 30)
//            ->get();
//        foreach ($msgFees as $msgFee) {
//            $shippingData = [
//                'driver_uuid' => $msgFee->driver_uuid,
//                'order_id'    => $msgFee->order_id,
//                'msg_fee_id'  => $msgFee->id,
//            ];
//            $ret = ShippingService::getInstance()->createShipping($shippingData);
//        }
//        dd('bug done');

        // 新增路线
//        $citys = RouteService::getInstance()->addOwnerRoute('d6ffa79b-fafb-3828-a856-6594edfad473',  '104.873643,27.436193', '116.480656,39.989677','方恒国际', '镇雄一中');
//        dd($citys);

        //支付测试
//        $payRet = PayService::getInstance()->payByApp(2, 'test098kiuojk', 100, 'ceshi');
//        dd($payRet);

        //查询支付结果
//        $ret = PayService::getInstance()->findPayStatus('or95c9b5fa7284c3', 2);
//        dd($ret);

        //echo uniqid('hfm');

        // 短信测试
        //$sms = $this->testSms();
        //dd($sms);

        // 上传图片测试
//        $file = $request->get('file');
//        $file = file_get_contents($file);
//        $res = $this->uploadByBuf($file);
//        $res = $res->original;
//        dd($res);
    }

    protected function testSms()
    {
        $code = mt_rand(1000, 9999);
        return Sms::send('18611551499', new VerificationCodeMessage($code));
    }

}
